using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;

public class ButtonBinder : BinderBase
{
    public enum AttributeType : int
    {
        onClick,
        interactable,
        enabled,
    }
    
    private Button _target;
    
    public ButtonBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public ButtonBinder()
    {
        
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<Button>();
        _active = _target != null;
    }
    public override void SetAction(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onClick:
                _target.onClick.AddListener(action);
            break;
            default:
            break;
        }
        base.SetAction(action);
    }
    
    public override void RemoveAction(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onClick:
                _target.onClick.RemoveListener(action);
            break;
            default:
            break;
        }
        base.RemoveAction(action);
    }
    
    public override void SetBoolean(bool value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.interactable:
                _target.interactable = value;
            break;
            case AttributeType.enabled:
                _target.enabled = value;
            break;
            default:
            break;
        }
        base.SetBoolean(value);
    }
    
    public override void RemoveAllAction()
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onClick:
                _target.onClick.RemoveAllListeners();
            break;
            default:
            break;
        }
    }
    
}